import { defineStore } from 'pinia'
export const useDistInfoStore = defineStore('dist', {
  state: () => {
    return {
        distInfo: JSON.parse(sessionStorage.getItem('distInfo')) || "",
        distInfoRoles: JSON.parse(sessionStorage.getItem('distInfoRoles')) || "",
    }
  },
  actions:{
    getDistInfo(name = ''){
        if((name??'') !== ''){
            let info = [];
            this.distInfo.forEach(value=>{
                if(value.groupName == name){
                    info = value.groupData;
                }
            })
            return info;
        }else{
            return this.distInfo;
        }
    },
    setDistInfo(log){
      this.distInfo = log;
      sessionStorage.setItem(`distInfo`, JSON.stringify(log))
    },
    removeDistInfo(){
      this.distInfo = "";
      sessionStorage.removeItem(`distInfo`)
    },
    // 加权限数据字典
    getDistInfos(name = ''){
      if((name??'') !== ''){
          let info = [];
          this.distInfoRoles.forEach(value=>{
              if(value.permissionName == name){
                  info = value.dataPermissionDtoList;
              }
            })
            return info;
        }else{
            return this.distInfoRoles;
        }
      },
      setDistInfos(log){
        this.distInfoRoles = log;
        sessionStorage.setItem(`distInfoRoles`, JSON.stringify(log))
      },
      removeDistInfos(){
        this.distInfoRoles = "";
        sessionStorage.removeItem(`distInfoRoles`)
      },
  }
})

